﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Test.Model;

namespace Test.DAL
{
   public class BaseDAL<T> where T:class
    {
        public Model1 Model
        {
            get
            {
                return new Model1();
            }
        }
        public List<T> Select(Expression<Func<T, bool>> expression)
        {
            return Model.Set<T>().Where(expression).ToList();
        }
        public T Single(Expression<Func<T, bool>> expression)
        {
            return Model.Set<T>().FirstOrDefault(expression);
        }

        public int Insert(T info)
        {
            Model.Set<T>().Add(info);
            return Model.SaveChanges();
        }
        public int Delete(T info)
        {
            Model.Set<T>().Remove(info);
            return Model.SaveChanges();
        }
        public T Single(int id)
        {
            return Model.Set<T>().Find(id);
        }
    }
}
